package com.hermes.biz.dao.user.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hermes.biz.common.model.user.UserCommentDO;
import com.hermes.biz.dao.user.UserCommentDAO;

public class UserCommentDAOImpl extends SqlMapClientDaoSupport implements UserCommentDAO{

	private Logger log = Logger.getLogger(UserCommentDAOImpl.class);
	
	/**
	 * 
	 */
	public void saveUserCommentInfo(UserCommentDO userCommentDO) {

				try {
					this.getSqlMapClientTemplate().getSqlMapClient().insert("UserCommentDAO.saveUserCommentInfo", userCommentDO);
				} catch (SQLException e) {
					log.error(e);
				}

	}

	/**
	 * 
	 */
	@SuppressWarnings("unchecked")
	public  List<UserCommentDO>  getUserCommentInfo(long userId) {
			try {
				return (List<UserCommentDO>) getSqlMapClientTemplate().getSqlMapClient().queryForList("UserCommentDAO.getUserCommentInfo", userId);
			} catch (SQLException e) {
				log.error(e);
			}
			return null;
	}

	/**
	 * 
	 *
	 */
	@SuppressWarnings("unchecked")
	public  List<UserCommentDO>  getUserCommentInfoByItemId(long itemId) {
				try {
					return (List<UserCommentDO>) getSqlMapClientTemplate().getSqlMapClient().queryForList("UserCommentDAO.getUserCommentInfoByItemId",itemId);
				} catch (SQLException e) {
					log.error(e);
				}
				return null;
	}

	/**
	 *
	 */
	public UserCommentDO getUserCommentInfoByCommentId(long commentId) {
				try {
					return (UserCommentDO) getSqlMapClientTemplate().getSqlMapClient().queryForObject("UserCommentDAO.getUserCommentInfoByCommentId", commentId);
				} catch (SQLException e) {
					log.error(e);
				}
				return null;
	}

	/**
	 * 
	 *
	 */
	public void deleteUserCommentInfo(long userId) {
				try {
					this.getSqlMapClientTemplate().getSqlMapClient().delete("UserCommentDAO.deleteUserCommentInfo",userId);
				} catch (SQLException e) {
					log.error(e);
				}
				
	}

	/**
	 * 
	 *
	 */
	public void deleteUserCommentInfoByCommentId(long commentId) {
				try {
					this.getSqlMapClientTemplate().getSqlMapClient().delete("UserCommentDAO.deleteUserCommentInfoByCommentId",commentId);
				} catch (SQLException e) {
					log.error(e);
				}
		
	}

	public void deleteUserCommentInfoByitemId(long itemId) {
				try {
					this.getSqlMapClientTemplate().getSqlMapClient().delete("UserCommentDAO.deleteUserCommentInfoByitemId",itemId);
				} catch (SQLException e) {
					log.error(e);
				}		
	}

	@SuppressWarnings("unchecked")
	public List<UserCommentDO> getUserCommentInfoByItemIdV2(long itemId) {
		try {
			return (List<UserCommentDO>) getSqlMapClientTemplate().getSqlMapClient().queryForList("UserCommentDAO.getUserCommentInfoByItemIdV2",itemId);
		} catch (SQLException e) {
			log.error(e);
		}
		return null;	
	}

}
